<!doctype html>
<html lang="zh_CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>demo</title>
    <style>
        /*必须写上，阻止ios默认长按事件*/
        img{-webkit-touch-callout: none;}
    </style>
</head>
<body style="height: 400px; width: 375px;overflow: hidden;position: relative;">
    <img id="longTap" height="400" src="">
    <input type="text" placeholder="这里输入文字弹出键盘">
    <p><a href="http://www.baidu.com">点击跳转到百度</a></p>
    <p style="height: 600px;background-color: beige">bg</p>
    <p style="height: 600px;background-color: beige">bg</p>
    <!-- 引入 jQuery 库 -->
    <script src="https://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>

    <!-- 引入 jQuery Mobile 库 -->
    <script src="https://cdn.bootcss.com/jquery-mobile/1.4.5/jquery.mobile.min.js"></script>
    <script>
        let url = document.getElementsByTagName('img')[0].src;
        let touchTimer = 0;

        $('#longTap').on('taphold',function (e) {
            save();
        });

        //保存图片，base64格式
        function save() {
            if(top){
                top.postMessage({saveImgUrl:url},'*');
            }
            console.log(123);
        }

        //监听touch事件，长按500ms触发
        function touchStart() {
            touchTimer = setTimeout('longPress()',500);
            return false;
        }

        function touchMove() {
            clearTimeout(touchTimer);
            touchTimer = 0;
            return false;
        }

        function touchEnd() {
            clearTimeout(touchTimer);
            return false;
        }
        
        function longPress() {
            clearTimeout(touchTimer);
            touchTimer = 0;
            save();
        }
    </script>
</body>
</html>
